package com.loeng.module.system.dal.mysql.user;

import com.loeng.framework.common.pojo.PageResult;
import com.loeng.framework.mybatis.core.mapper.BaseMapperX;
import com.loeng.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.loeng.module.system.controller.admin.user.vo.UsersPageReqVO;
import com.loeng.module.system.dal.dataobject.user.AdminUserDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 用户 Mapper
 * @author loeng zhuo
 */
@Mapper
public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {

    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户
     */
    default AdminUserDO getUserByUsername(String username) {
        return selectOne(AdminUserDO::getUsername, username);
    }

    default PageResult<AdminUserDO> selectPage(UsersPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AdminUserDO>()
                .likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
                .eqIfPresent(AdminUserDO::getPassword, reqVO.getPassword())
                .likeIfPresent(AdminUserDO::getNickname, reqVO.getNickname())
                .eqIfPresent(AdminUserDO::getRemark, reqVO.getRemark())
                .eqIfPresent(AdminUserDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(AdminUserDO::getPostIds, reqVO.getPostIds())
                .eqIfPresent(AdminUserDO::getEmail, reqVO.getEmail())
                .eqIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
                .eqIfPresent(AdminUserDO::getSex, reqVO.getSex())
                .eqIfPresent(AdminUserDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
                .eqIfPresent(AdminUserDO::getLoginIp, reqVO.getLoginIp())
                .betweenIfPresent(AdminUserDO::getLoginDate, reqVO.getLoginDate())
                .betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AdminUserDO::getId));
    }

    /**
     * 根据状态查询用户
     * @param status 状态
     * @return 用户
     */
    default List<AdminUserDO> selectListByStatus(Integer status) {
        return selectList(AdminUserDO::getStatus, status);
    }

}
